// Register Objects
// (c) jimon game studio

#include "jeRegisterObjects.h"
#include "ISceneManager.h"

namespace je
{
	namespace scene
	{
		template <class T>
		class SceneNodeFactoryCreator:public ISceneManager::NodeFactoryType::BaseTypeCreator
		{
		protected:
			ISceneManager * CurrentSceneManager;
		public:
			SceneNodeFactoryCreator(ISceneManager * SceneManager):CurrentSceneManager(SceneManager){}
			ISceneNode * Create()
			{
				ISceneNode * NewCreate = NULL;
				JENEW(NewCreate, T(CurrentSceneManager->GetRender()) )
				return NewCreate;
			}
			static void Register(ISceneManager * SceneManager,const jeStringc & Name)
			{
				ISceneManager::NodeFactoryType::BaseTypeCreator * Creator = NULL;
				JENEW(Creator,SceneNodeFactoryCreator<T>(SceneManager))
				SceneManager->GetNodeFactory()->RegisterDiscribedClass(Name,Creator);
			}
		};

		template <class T>
		class AnimatorFactoryCreator:public ISceneManager::AnimatorFactoryType::BaseTypeCreator
		{
		public:
			AnimatorFactoryCreator(){}
			IAnimator * Create()
			{
				IAnimator * NewCreate = NULL;
				JENEW(NewCreate, T )
				return NewCreate;
			}
			static void Register(ISceneManager * SceneManager,const jeStringc & Name)
			{
				ISceneManager::AnimatorFactoryType::BaseTypeCreator * Creator = NULL;
				JENEW(Creator,AnimatorFactoryCreator<T>)
				SceneManager->GetAnimatorFactory()->RegisterDiscribedClass(Name,Creator);
			}
		};

		template <class T>
		class CompositorFactoryCreator:public ISceneManager::CompositorFactoryType::BaseTypeCreator
		{
		protected:
			ISceneManager * CurrentSceneManager;
		public:
			CompositorFactoryCreator(ISceneManager * SceneManager):CurrentSceneManager(SceneManager){}
			ICompositor * Create()
			{
				ICompositor * NewCreate = NULL;
				JENEW(NewCreate, T(CurrentSceneManager) )
				return NewCreate;
			}
			static void Register(ISceneManager * SceneManager,const jeStringc & Name)
			{
				ISceneManager::CompositorFactoryType::BaseTypeCreator * Creator = NULL;
				JENEW(Creator,CompositorFactoryCreator<T>(SceneManager))
				SceneManager->GetCompositorFactory()->RegisterDiscribedClass(Name,Creator);
			}
		};

		//! Register Objects
		void JE_GAME_FUNCTION_CALL RegisterObjects(ISceneManager * SceneManager)
		{
			#define SREG(__c,__n) SceneNodeFactoryCreator<__c>::Register(SceneManager,__n);
			#define SREGM(__n) SREG(C##__n,#__n)

			#define AREG(__c,__n) AnimatorFactoryCreator<__c>::Register(SceneManager,__n);
			#define AREGM(__n) AREG(je##__n,#__n)

			#define CREG(__c,__n) CompositorFactoryCreator<__c>::Register(SceneManager,__n);
			#define CREGM(__n) CREG(je##__n,#__n)
		}
	}
}
